﻿namespace CN2P.Web.Db
{
    using System;
    using CN2P.ServiceModel;

    public partial class Order
    {

        public static Order From(OrderModel model)
        {
            var order = new Order
            {
                Id = Math.Abs(Guid.NewGuid().GetHashCode()).ToString(),
                UserId = model.UserId,
                TotalValue = model.TotalValue,
                OrderDate = DateTime.Now,
            };

            foreach (var item in model.Items)
            {
                order.OrderItems.Add(OrderItem.From(item));
            }

            return order;
        }
    }
}